package cn.itsource.basic.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 返回数据封装类
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {

    private String code = PetConstant.SYS_SUCCESS;

    private String message = "成功";

    private Boolean success = true;

    private Object data;

    /**
     * 返回成功信息
     */
    public static JsonResult createSuccess(){
        return new JsonResult();
    }

    /**
     * 返回成功信息, 携带数据
     */
    public static JsonResult createSuccess(Object data){
        return new JsonResult(PetConstant.SYS_SUCCESS,"成功",true,data);
    }
    public static JsonResult createSuccess(String message,String data){
        return new JsonResult(PetConstant.SYS_SUCCESS,message,true,data);
    }
    public static JsonResult createSuccess(String message){
        return new JsonResult(PetConstant.SYS_SUCCESS,message,true,null);
    }


    /**
     * 返回错误信息 message
     */
    public static JsonResult createError(String message){
        return new JsonResult(PetConstant.SYS_ERROR,message,false,null);
    }

    /**
     * 返回错误信息 message 状态码code
     * @param code
     * @param message
     * @return
     */
    public static JsonResult createError(String code,String message){
        return new JsonResult(code,message,false,null);
    }

}
